package crl.encrypt.ext
{
	import com.swfwire.decompiler.SWFReaderContext;
	import com.swfwire.decompiler.data.swf.records.TagHeaderRecord;
	import com.swfwire.decompiler.data.swf.tags.SWFTag;
	import com.swfwire.decompiler.data.swf9.tags.DefineBinaryDataTag;
	
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;

	public class ExportSWFReader extends ExAsyncSWFReader
	{
		public function ExportSWFReader()
		{
			super();
		}
		
		override protected function readTag(context:SWFReaderContext, header:TagHeaderRecord):SWFTag
		{
			var tag:SWFTag;
			switch(header.type)
			{
				case 76:
					tag = readSymbolClassTag(context, header);
					break;
				case 72:
					tag=readDoABCDeprecatedTag(context, header);
					break;
				case 82:
					tag = readDoABCTag(context, header);
					break;
				case 87 :
					tag=readDefineBinaryDataTag(context,header);
					break;
				case 0:
					tag = readEndTag(context, header);
					break;
				default:
					tag = readUnknownTag(context, header);
					break;
			}
			
			//trace(header.type)
			return tag;
		}
		
		
		override protected function readDefineBinaryDataTag(context:SWFReaderContext, header:TagHeaderRecord):DefineBinaryDataTag{
			var a:DefineBinaryDataTag= super.readDefineBinaryDataTag(context,header);
			
			var file:File=File.desktopDirectory.resolvePath("DefineBinaryData/"+a.characterId+".swf");
			
			var stream:FileStream=new FileStream();
			stream.open(file,FileMode.WRITE);
			stream.writeBytes(a.data);
			stream.close();
			
			return a;
		}
	}
}